package main.java.LeetCode.ClassicalAlgorithm.Worker.Impl;

import main.java.LeetCode.ClassicalAlgorithm.Queue.Impl.LinkedBlockQueue;
import main.java.LeetCode.ClassicalAlgorithm.Queue.Queue;
import main.java.LeetCode.ClassicalAlgorithm.Worker.Impl.chain.GlobalChain;
import main.java.LeetCode.ClassicalAlgorithm.Worker.Impl.chain.Source;

import java.util.concurrent.TimeUnit;

public class Demo {
    public static void main(String[] args) throws InterruptedException {
        GlobalChain<Integer, String> globalChain = new GlobalChain<>(integer -> "已完成: "+integer);
        LinkedBlockQueue<Integer> queue = new LinkedBlockQueue<>(8);
        for (int i = 0; i < 8; i++) {
            queue.offer(i);
        }

        Source<Integer> source = new Source<>();
        source.setOut(queue);
        GlobalChain<Integer, String> stringChain = source.link(globalChain);
        Queue<String> out = stringChain.getOut();

        source.flow();

        String s;
        while ((s = out.get(1,TimeUnit.SECONDS))!=null){
            System.out.println(s);
        }
    }
}
